#include <bits/stdc++.h>
#define pb push_back
#define m_p make_pair
#define fi first
#define se second
#define lowbit(i) i&(-i)
#define siz(s) (int)s.size()
#define pair<int,int> pi
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
const int Maxn=2e5+10;
int a[Maxn],bi[Maxn];
inline void solve(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll ans=-1;
    for(int i=0;i<(1<<n);i++){
        ll res=0;
        for(int j=1;j<=n;j++){
            if(i&(1<<(j-1))) bi[n-j+1]=1;
            else bi[n-j+1]=0;
        }
        for(int j=1;j<=n;j++){
            int loc=-1;
            for(int k=j-1;k>=1;k--){
                if(bi[k]==bi[j]){
                    loc=k;
                    break;
                }
            }
            if(!(~loc)) continue;
            else if(a[j]==a[loc]) res+=a[j];
            // if(i==218) printf("%d %d\n",j,loc);
        }
        // printf("%d %lld\n",i,res);
        ans=max(ans,res);
    }
    printf("%lld\n",ans);
}
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    int t;
    scanf("%d",&t);
    while(t--) solve();
    return 0; 
}